class Solution1:
    def merge(self, nums1: list[int], m: int, nums2: list[int], n: int) -> None:
        """
        Do not return anything, modify nums1 in-place instead.
        """
        ptr1, ptr2, length, idx = 0, 0, m + n, 0
        arr = [0] * length
        while ptr1 < m or ptr2 < n:
            if ptr1 == m:
                arr[idx] = nums2[ptr2]
                ptr2 += 1
            elif ptr2 == n:
                arr[idx] = nums1[ptr1]
                ptr1 += 1
            elif nums1[ptr1] <= nums2[ptr2]:
                arr[idx] = nums1[ptr1]
                ptr1 += 1
            else:
                arr[idx] = nums2[ptr2]
                ptr2 += 1
            idx += 1
        for i in range(length):
            nums1[i] = arr[i]


class Solution2:
    def merge(self, nums1: list[int], m: int, nums2: list[int], n: int) -> None:
        """
        Do not return anything, modify nums1 in-place instead.
        """
        ptr1, ptr2, idx = m - 1, n - 1, m + n - 1
        while ptr1 > -1 or ptr2 > -1:
            if ptr1 == -1 or nums1[ptr1] <= nums2[ptr2]:
                nums1[idx] = nums2[ptr2]
                ptr2 -= 1
            elif ptr2 == -1:
                nums2[idx] = nums1[ptr1]
                ptr1 -= 1
            elif nums1[ptr1] <= nums2[ptr2]:
                nums1[idx] = nums2[ptr2]
                ptr2 -= 1
            else:
                nums1[idx] = nums1[ptr1]
                ptr1 -= 1
            idx -= 1


class Solution3:
    def merge(self, nums1: list[int], m: int, nums2: list[int], n: int) -> None:
        """
        Do not return anything, modify nums1 in-place instead.
        """
        arr = nums1[:m] + nums2
        arr.sort()
        nums1[:] = arr[:]
